gridview: Don't assert on a condition that can happen
authorMatthias Clasen <mclasen@redhat.com>
Sat, 20 Jun 2020 16:11:59 +0000 (12:11 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 20 Jun 2020 16:11:59 +0000 (12:11 -0400)
We are currently not robust against model changes or
widget invalidations, so we can actually end up in
situations where we run out of items here. Handle
the failure a bit more gracefully, by returning NULL.

This is good enough to make scrolling work okish most
of the time. We still need a proper fix to handle
other situations.

gtk/gtkgridview.c

index b9c2c9a87ce2bc45d4972f2d222626a02b8c3fcf..5b2a381c6902b0ece63ce745930debbd45ea99b3 100644 (file)
@@ -270,7 +270,17 @@ gtk_grid_view_get_cell_at_y (GtkGridView *self,
       if (pos % self->n_columns)
         {
           skip = self->n_columns - pos % self->n_columns;
-          g_assert (n_items > skip);
+          if (n_items <= skip)
+            {
+              g_warning ("ran out of items");
+              if (position)
+                *position = 0;
+              if (offset)
+                *offset = 0;
+              if (size)
+                *size = 0;
+              return NULL;
+            }
           n_items -= skip;
           pos += skip;
         }